package revolucion.window;

import revolucion.classes.User;
import revolucion.classes.Log;
import revolucion.database.Database;

import java.applet.AudioClip;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.Timer;
import javax.swing.UIManager;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;

import java.sql.ResultSet;

import org.pushingpixels.substance.api.skin.*;

public class Window_Main extends JFrame {
  User user;
  DefaultTableModel md;
  ResultSet chatMessages;
  ResultSet usersOnline;
  DefaultListModel modelUsersOnline;
  AudioClip newMessage;

  public Window_Main( User _user ) {
    super ( ".:: Revolución Admin 1.0 || Revolución Development Team" );

    user = _user;
    user.setStatus( user, "online" );

    initComponents();

    setIconImage(new ImageIcon(getClass().getResource("/revolucion/resources/admin.gif")).getImage());

    try {
      md = Database.getUsersTableModel();
      tab_users.setModel( md );

      md = Database.getRegisteredsTableModel();
      tab_registereds.setModel( md );
    } catch ( Exception ex ) {
      ex.printStackTrace();
    }
    
    ActionListener updateChat = new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        try {
          // Carrega mensagens
          chatMessages = Database.getChatMessages();

          String messages = "";

          while(chatMessages.next()){
            messages += "» " + chatMessages.getString("owner") + " disse:\n" + chatMessages.getString("message") + "\n\n";
          }

          txt_chatPanel.setText( messages );


          // Carrega usuários online
          usersOnline = Database.getUsersOnline();
          modelUsersOnline = new DefaultListModel();

          while(usersOnline.next()){
            modelUsersOnline.addElement(usersOnline.getString("displayName"));
          }

          lst_chatUsers.setModel(modelUsersOnline);
        } catch ( Exception e ){
          e.printStackTrace();
        }
      }  
    };

    Timer t = new Timer(1000, updateChat);
    t.start();

    Dimension dim = this.getToolkit().getScreenSize();
    int x = (int) (dim.getWidth()  - this.getSize().getWidth() ) / 2;
    int y = (int) (dim.getHeight() - this.getSize().getHeight()) / 2;
    this.setLocation(x,y);
  }

  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    bgp_skin = new javax.swing.ButtonGroup();
    jTabbedPane1 = new javax.swing.JTabbedPane();
    jPanel9 = new javax.swing.JPanel();
    jPanel1 = new javax.swing.JPanel();
    jToolBar1 = new javax.swing.JToolBar();
    btn_addUser = new javax.swing.JButton();
    btn_editUser = new javax.swing.JButton();
    jButton4 = new javax.swing.JButton();
    btn_searchUser = new javax.swing.JButton();
    jSeparator2 = new javax.swing.JToolBar.Separator();
    jButton3 = new javax.swing.JButton();
    jScrollPane1 = new javax.swing.JScrollPane();
    tab_users = new javax.swing.JTable();
    jPanel10 = new javax.swing.JPanel();
    jToolBar3 = new javax.swing.JToolBar();
    jButton5 = new javax.swing.JButton();
    jButton6 = new javax.swing.JButton();
    jButton7 = new javax.swing.JButton();
    jButton8 = new javax.swing.JButton();
    jSeparator3 = new javax.swing.JToolBar.Separator();
    jButton9 = new javax.swing.JButton();
    jScrollPane5 = new javax.swing.JScrollPane();
    tab_registereds = new javax.swing.JTable();
    jPanel2 = new javax.swing.JPanel();
    jPanel3 = new javax.swing.JPanel();
    jPanel4 = new javax.swing.JPanel();
    jPanel5 = new javax.swing.JPanel();
    jPanel7 = new javax.swing.JPanel();
    jPanel8 = new javax.swing.JPanel();
    jLabel1 = new javax.swing.JLabel();
    jScrollPane2 = new javax.swing.JScrollPane();
    lst_chatUsers = new javax.swing.JList();
    jScrollPane3 = new javax.swing.JScrollPane();
    txt_chatPanel = new javax.swing.JTextPane();
    jScrollPane4 = new javax.swing.JScrollPane();
    txt_chatEdit = new javax.swing.JTextPane();
    btn_sendMessage = new javax.swing.JButton();
    jPanel11 = new javax.swing.JPanel();
    jPanel6 = new javax.swing.JPanel();
    jToolBar2 = new javax.swing.JToolBar();
    jButton1 = new javax.swing.JButton();
    jSeparator1 = new javax.swing.JToolBar.Separator();
    jButton2 = new javax.swing.JButton();
    jMenuBar1 = new javax.swing.JMenuBar();
    mnu_arquivo = new javax.swing.JMenu();
    jMenuItem1 = new javax.swing.JMenuItem();
    mnu_edit = new javax.swing.JMenu();
    jMenu1 = new javax.swing.JMenu();
    rdb_duskSkin = new javax.swing.JRadioButtonMenuItem();
    rdb_graphiteSkin = new javax.swing.JRadioButtonMenuItem();
    rdb_officeBlueSkin = new javax.swing.JRadioButtonMenuItem();
    rdb_officeSilverSkin = new javax.swing.JRadioButtonMenuItem();
    jMenu2 = new javax.swing.JMenu();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setLocationByPlatform(true);
    addWindowListener(new java.awt.event.WindowAdapter() {
      public void windowClosed(java.awt.event.WindowEvent evt) {
        formWindowClosed(evt);
      }
      public void windowClosing(java.awt.event.WindowEvent evt) {
        formWindowClosing(evt);
      }
    });

    jTabbedPane1.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT);
    jTabbedPane1.setTabPlacement(javax.swing.JTabbedPane.LEFT);
    jTabbedPane1.setName("jTabbedPane1"); // NOI18N

    jPanel9.setName("jPanel9"); // NOI18N

    javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
    jPanel9.setLayout(jPanel9Layout);
    jPanel9Layout.setHorizontalGroup(
      jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 554, Short.MAX_VALUE)
    );
    jPanel9Layout.setVerticalGroup(
      jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 489, Short.MAX_VALUE)
    );

    jTabbedPane1.addTab("Geral", new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/mini2-gear.png")), jPanel9); // NOI18N

    jPanel1.setName("jPanel1"); // NOI18N

    jToolBar1.setFloatable(false);
    jToolBar1.setRollover(true);
    jToolBar1.setName("jToolBar1"); // NOI18N

    btn_addUser.setIcon(new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/admin_add.gif"))); // NOI18N
    btn_addUser.setFocusable(false);
    btn_addUser.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    btn_addUser.setName("btn_addUser"); // NOI18N
    btn_addUser.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    btn_addUser.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        btn_addUserActionPerformed(evt);
      }
    });
    jToolBar1.add(btn_addUser);

    btn_editUser.setIcon(new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/admin_edit.gif"))); // NOI18N
    btn_editUser.setFocusable(false);
    btn_editUser.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    btn_editUser.setName("btn_editUser"); // NOI18N
    btn_editUser.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    btn_editUser.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        btn_editUserActionPerformed(evt);
      }
    });
    jToolBar1.add(btn_editUser);

    jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/admin_delete.gif"))); // NOI18N
    jButton4.setFocusable(false);
    jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jButton4.setName("jButton4"); // NOI18N
    jButton4.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jButton4.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton4ActionPerformed(evt);
      }
    });
    jToolBar1.add(jButton4);

    btn_searchUser.setIcon(new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/search.png"))); // NOI18N
    btn_searchUser.setFocusable(false);
    btn_searchUser.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    btn_searchUser.setName("btn_searchUser"); // NOI18N
    btn_searchUser.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jToolBar1.add(btn_searchUser);

    jSeparator2.setName("jSeparator2"); // NOI18N
    jToolBar1.add(jSeparator2);

    jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/refresh.gif"))); // NOI18N
    jButton3.setToolTipText("Atualizar");
    jButton3.setFocusable(false);
    jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jButton3.setName("jButton3"); // NOI18N
    jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jButton3.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton3ActionPerformed(evt);
      }
    });
    jToolBar1.add(jButton3);

    jScrollPane1.setName("jScrollPane1"); // NOI18N

    tab_users.setModel(new javax.swing.table.DefaultTableModel(
      new Object [][] {
        {null, null, null},
        {null, null, null},
        {null, null, null},
        {null, null, null}
      },
      new String [] {
        "Usuário", "Nome", "Email"
      }
    ) {
      Class[] types = new Class [] {
        java.lang.String.class, java.lang.String.class, java.lang.String.class
      };
      boolean[] canEdit = new boolean [] {
        false, false, false
      };

      public Class getColumnClass(int columnIndex) {
        return types [columnIndex];
      }

      public boolean isCellEditable(int rowIndex, int columnIndex) {
        return canEdit [columnIndex];
      }
    });
    tab_users.setName("tab_users"); // NOI18N
    jScrollPane1.setViewportView(tab_users);

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 554, Short.MAX_VALUE)
      .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 554, Short.MAX_VALUE)
    );
    jPanel1Layout.setVerticalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel1Layout.createSequentialGroup()
        .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 458, Short.MAX_VALUE))
    );

    jTabbedPane1.addTab("Usuários", new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/admin.gif")), jPanel1); // NOI18N

    jPanel10.setName("jPanel10"); // NOI18N

    jToolBar3.setFloatable(false);
    jToolBar3.setRollover(true);
    jToolBar3.setName("jToolBar3"); // NOI18N

    jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/user_add.gif"))); // NOI18N
    jButton5.setFocusable(false);
    jButton5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jButton5.setName("jButton5"); // NOI18N
    jButton5.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jToolBar3.add(jButton5);

    jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/user_edit.gif"))); // NOI18N
    jButton6.setFocusable(false);
    jButton6.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jButton6.setName("jButton6"); // NOI18N
    jButton6.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jToolBar3.add(jButton6);

    jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/user_delete.gif"))); // NOI18N
    jButton7.setFocusable(false);
    jButton7.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jButton7.setName("jButton7"); // NOI18N
    jButton7.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jToolBar3.add(jButton7);

    jButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/search.png"))); // NOI18N
    jButton8.setFocusable(false);
    jButton8.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jButton8.setName("jButton8"); // NOI18N
    jButton8.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jToolBar3.add(jButton8);

    jSeparator3.setName("jSeparator3"); // NOI18N
    jToolBar3.add(jSeparator3);

    jButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/refresh.gif"))); // NOI18N
    jButton9.setFocusable(false);
    jButton9.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jButton9.setName("jButton9"); // NOI18N
    jButton9.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jToolBar3.add(jButton9);

    jScrollPane5.setName("jScrollPane5"); // NOI18N

    tab_registereds.setModel(new javax.swing.table.DefaultTableModel(
      new Object [][] {
        {null, null, null, null},
        {null, null, null, null},
        {null, null, null, null},
        {null, null, null, null}
      },
      new String [] {
        "Title 1", "Title 2", "Title 3", "Title 4"
      }
    ));
    tab_registereds.setName("tab_registereds"); // NOI18N
    jScrollPane5.setViewportView(tab_registereds);

    javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
    jPanel10.setLayout(jPanel10Layout);
    jPanel10Layout.setHorizontalGroup(
      jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jToolBar3, javax.swing.GroupLayout.DEFAULT_SIZE, 554, Short.MAX_VALUE)
      .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 554, Short.MAX_VALUE)
    );
    jPanel10Layout.setVerticalGroup(
      jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel10Layout.createSequentialGroup()
        .addComponent(jToolBar3, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 458, Short.MAX_VALUE))
    );

    jTabbedPane1.addTab("Cadastros", new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/usuario.gif")), jPanel10); // NOI18N

    jPanel2.setName("jPanel2"); // NOI18N

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
      jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 554, Short.MAX_VALUE)
    );
    jPanel2Layout.setVerticalGroup(
      jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 489, Short.MAX_VALUE)
    );

    jTabbedPane1.addTab("Posts", new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/post.gif")), jPanel2); // NOI18N

    jPanel3.setName("jPanel3"); // NOI18N

    javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
    jPanel3.setLayout(jPanel3Layout);
    jPanel3Layout.setHorizontalGroup(
      jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 554, Short.MAX_VALUE)
    );
    jPanel3Layout.setVerticalGroup(
      jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 489, Short.MAX_VALUE)
    );

    jTabbedPane1.addTab("Imagens", new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/images.gif")), jPanel3); // NOI18N

    jPanel4.setName("jPanel4"); // NOI18N

    javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
    jPanel4.setLayout(jPanel4Layout);
    jPanel4Layout.setHorizontalGroup(
      jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 554, Short.MAX_VALUE)
    );
    jPanel4Layout.setVerticalGroup(
      jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 489, Short.MAX_VALUE)
    );

    jTabbedPane1.addTab("Vídeos", new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/video.gif")), jPanel4); // NOI18N

    jPanel5.setName("jPanel5"); // NOI18N

    javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
    jPanel5.setLayout(jPanel5Layout);
    jPanel5Layout.setHorizontalGroup(
      jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 554, Short.MAX_VALUE)
    );
    jPanel5Layout.setVerticalGroup(
      jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 489, Short.MAX_VALUE)
    );

    jTabbedPane1.addTab("Músicas", new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/music.gif")), jPanel5); // NOI18N

    jPanel7.setName("jPanel7"); // NOI18N

    jPanel8.setName("jPanel8"); // NOI18N

    jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12));
    jLabel1.setText("Usuários online");
    jLabel1.setName("jLabel1"); // NOI18N

    jScrollPane2.setName("jScrollPane2"); // NOI18N

    lst_chatUsers.setName("lst_chatUsers"); // NOI18N
    jScrollPane2.setViewportView(lst_chatUsers);

    javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
    jPanel8.setLayout(jPanel8Layout);
    jPanel8Layout.setHorizontalGroup(
      jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel8Layout.createSequentialGroup()
        .addContainerGap(31, Short.MAX_VALUE)
        .addComponent(jLabel1)
        .addGap(29, 29, 29))
      .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 152, Short.MAX_VALUE)
    );
    jPanel8Layout.setVerticalGroup(
      jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel8Layout.createSequentialGroup()
        .addContainerGap()
        .addComponent(jLabel1)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 446, Short.MAX_VALUE)
        .addContainerGap())
    );

    jScrollPane3.setName("jScrollPane3"); // NOI18N

    txt_chatPanel.setEditable(false);
    txt_chatPanel.setFocusable(false);
    txt_chatPanel.setName("txt_chatPanel"); // NOI18N
    jScrollPane3.setViewportView(txt_chatPanel);

    jScrollPane4.setName("jScrollPane4"); // NOI18N

    txt_chatEdit.setMaximumSize(new java.awt.Dimension(6, 20));
    txt_chatEdit.setName("txt_chatEdit"); // NOI18N
    txt_chatEdit.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        txt_chatEditKeyPressed(evt);
      }
    });
    jScrollPane4.setViewportView(txt_chatEdit);

    btn_sendMessage.setText("Enviar");
    btn_sendMessage.setName("btn_sendMessage"); // NOI18N
    btn_sendMessage.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        btn_sendMessageActionPerformed(evt);
      }
    });

    javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
    jPanel7.setLayout(jPanel7Layout);
    jPanel7Layout.setHorizontalGroup(
      jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE)
          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(btn_sendMessage)))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
        .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    );
    jPanel7Layout.setVerticalGroup(
      jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      .addGroup(jPanel7Layout.createSequentialGroup()
        .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 432, Short.MAX_VALUE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
          .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(btn_sendMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addContainerGap())
    );

    jTabbedPane1.addTab("Chat", new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/posts.gif")), jPanel7); // NOI18N

    jPanel11.setName("jPanel11"); // NOI18N

    javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
    jPanel11.setLayout(jPanel11Layout);
    jPanel11Layout.setHorizontalGroup(
      jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 554, Short.MAX_VALUE)
    );
    jPanel11Layout.setVerticalGroup(
      jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 489, Short.MAX_VALUE)
    );

    jTabbedPane1.addTab("Intercessão", new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/intercessao.gif")), jPanel11); // NOI18N

    jPanel6.setName("jPanel6"); // NOI18N

    jToolBar2.setBorder(null);
    jToolBar2.setFloatable(false);
    jToolBar2.setRollover(true);
    jToolBar2.setName("jToolBar2"); // NOI18N

    jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/imprimir.gif"))); // NOI18N
    jButton1.setToolTipText("Imprimir Relatório");
    jButton1.setFocusable(false);
    jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jButton1.setName("jButton1"); // NOI18N
    jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jToolBar2.add(jButton1);

    jSeparator1.setName("jSeparator1"); // NOI18N
    jToolBar2.add(jSeparator1);

    jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/log.gif"))); // NOI18N
    jButton2.setToolTipText("Logs");
    jButton2.setFocusable(false);
    jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jButton2.setName("jButton2"); // NOI18N
    jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jButton2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton2ActionPerformed(evt);
      }
    });
    jToolBar2.add(jButton2);

    javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
    jPanel6.setLayout(jPanel6Layout);
    jPanel6Layout.setHorizontalGroup(
      jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jToolBar2, javax.swing.GroupLayout.DEFAULT_SIZE, 554, Short.MAX_VALUE)
    );
    jPanel6Layout.setVerticalGroup(
      jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel6Layout.createSequentialGroup()
        .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addContainerGap(464, Short.MAX_VALUE))
    );

    jTabbedPane1.addTab("Relatórios", new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/relatorios.gif")), jPanel6); // NOI18N

    jMenuBar1.setName("jMenuBar1"); // NOI18N

    mnu_arquivo.setText("Arquivo");
    mnu_arquivo.setName("mnu_arquivo"); // NOI18N

    jMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/close.gif"))); // NOI18N
    jMenuItem1.setText("Sair");
    jMenuItem1.setName("jMenuItem1"); // NOI18N
    jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuItem1ActionPerformed(evt);
      }
    });
    mnu_arquivo.add(jMenuItem1);

    jMenuBar1.add(mnu_arquivo);

    mnu_edit.setText("Editar");
    mnu_edit.setName("mnu_edit"); // NOI18N

    jMenu1.setText("Aparência");
    jMenu1.setName("jMenu1"); // NOI18N

    bgp_skin.add(rdb_duskSkin);
    rdb_duskSkin.setText("Dust");
    rdb_duskSkin.setName("rdb_duskSkin"); // NOI18N
    rdb_duskSkin.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        rdb_duskSkinActionPerformed(evt);
      }
    });
    jMenu1.add(rdb_duskSkin);

    bgp_skin.add(rdb_graphiteSkin);
    rdb_graphiteSkin.setSelected(true);
    rdb_graphiteSkin.setText("Graphite");
    rdb_graphiteSkin.setName("rdb_graphiteSkin"); // NOI18N
    rdb_graphiteSkin.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        rdb_graphiteSkinActionPerformed(evt);
      }
    });
    jMenu1.add(rdb_graphiteSkin);

    bgp_skin.add(rdb_officeBlueSkin);
    rdb_officeBlueSkin.setText("Office Blue");
    rdb_officeBlueSkin.setName("rdb_officeBlueSkin"); // NOI18N
    rdb_officeBlueSkin.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        rdb_officeBlueSkinActionPerformed(evt);
      }
    });
    jMenu1.add(rdb_officeBlueSkin);

    bgp_skin.add(rdb_officeSilverSkin);
    rdb_officeSilverSkin.setText("Office Silver");
    rdb_officeSilverSkin.setName("rdb_officeSilverSkin"); // NOI18N
    rdb_officeSilverSkin.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        rdb_officeSilverSkinActionPerformed(evt);
      }
    });
    jMenu1.add(rdb_officeSilverSkin);

    mnu_edit.add(jMenu1);

    jMenuBar1.add(mnu_edit);

    jMenu2.setText("Ajuda");
    jMenu2.setName("jMenu2"); // NOI18N
    jMenuBar1.add(jMenu2);

    setJMenuBar(jMenuBar1);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 661, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 494, Short.MAX_VALUE)
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

    private void rdb_duskSkinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdb_duskSkinActionPerformed
      try {
        UIManager.setLookAndFeel(new SubstanceDustLookAndFeel());
        SwingUtilities.updateComponentTreeUI(this);
      } catch (Exception e) {
        System.out.println("Substance Dust failed to initialize");
      }
    }//GEN-LAST:event_rdb_duskSkinActionPerformed

    private void rdb_graphiteSkinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdb_graphiteSkinActionPerformed
      try {
        UIManager.setLookAndFeel(new SubstanceGraphiteAquaLookAndFeel());
        SwingUtilities.updateComponentTreeUI(this);
      } catch (Exception e) {
        System.out.println("Substance Graphite Aqua failed to initialize");
      }
    }//GEN-LAST:event_rdb_graphiteSkinActionPerformed

    private void rdb_officeBlueSkinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdb_officeBlueSkinActionPerformed
      try {
        UIManager.setLookAndFeel(new SubstanceOfficeBlue2007LookAndFeel());
        SwingUtilities.updateComponentTreeUI(this);
      } catch (Exception e) {
        System.out.println("Substance Office Blue 2007 failed to initialize");
      }
    }//GEN-LAST:event_rdb_officeBlueSkinActionPerformed

    private void rdb_officeSilverSkinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdb_officeSilverSkinActionPerformed
      try {
        UIManager.setLookAndFeel(new SubstanceOfficeSilver2007LookAndFeel());
        SwingUtilities.updateComponentTreeUI(this);
      } catch (Exception e) {
        System.out.println("Substance Office Silver 2007 failed to initialize");
      }
    }//GEN-LAST:event_rdb_officeSilverSkinActionPerformed

    private void btn_editUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_editUserActionPerformed
      User userSelected = new User();
      userSelected.loadUser( this.tab_users.getModel().getValueAt(this.tab_users.getSelectedRow(), 0).toString() );
      Window_User w = new Window_User(true, userSelected, user, tab_users);
      w.setVisible(true);
    }//GEN-LAST:event_btn_editUserActionPerformed

    private void btn_addUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_addUserActionPerformed
      Window_User w = new Window_User(false, null, user, tab_users);
      w.setVisible(true);
    }//GEN-LAST:event_btn_addUserActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
      this.dispose();
}//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
      Window_PassDialog w = new Window_PassDialog("logs", user);
      w.setVisible(true);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
      Log.writeLog(user.getUsername(), "Usuário encerrou sessão.", "OK");
    }//GEN-LAST:event_formWindowClosed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
      Log.writeLog(user.getUsername(), "Usuário encerrou sessão.", "OK");
      user.setStatus( user, "offline" );
    }//GEN-LAST:event_formWindowClosing

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
      DefaultTableModel md = Database.getUsersTableModel();
      tab_users.setModel(md);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void txt_chatEditKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_chatEditKeyPressed
      if(evt.getKeyCode() == KeyEvent.VK_ENTER) {
        btn_sendMessage.doClick();
      }
    }//GEN-LAST:event_txt_chatEditKeyPressed

    private void btn_sendMessageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_sendMessageActionPerformed
      Database.sendChatMessage(user.getDisplayName(), txt_chatEdit.getText());
    }//GEN-LAST:event_btn_sendMessageActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
      String selectedUser = this.tab_users.getModel().getValueAt(this.tab_users.getSelectedRow(), 0).toString();

      if(JOptionPane.showConfirmDialog(this, "Deletar usuário " + selectedUser + "?") == 0){
        Database.deleteUser(selectedUser);
        JOptionPane.showMessageDialog(this, "Usuário deletado!");
        
        Log.writeLog(user.getUsername(), "Usuário " + selectedUser + " deletado.", "OK");

        DefaultTableModel md = Database.getUsersTableModel();
        tab_users.setModel(md);
      }
    }//GEN-LAST:event_jButton4ActionPerformed

  // Variables declaration - do not modify//GEN-BEGIN:variables
  javax.swing.ButtonGroup bgp_skin;
  javax.swing.JButton btn_addUser;
  javax.swing.JButton btn_editUser;
  javax.swing.JButton btn_searchUser;
  public javax.swing.JButton btn_sendMessage;
  javax.swing.JButton jButton1;
  javax.swing.JButton jButton2;
  javax.swing.JButton jButton3;
  javax.swing.JButton jButton4;
  javax.swing.JButton jButton5;
  javax.swing.JButton jButton6;
  javax.swing.JButton jButton7;
  javax.swing.JButton jButton8;
  javax.swing.JButton jButton9;
  javax.swing.JLabel jLabel1;
  javax.swing.JMenu jMenu1;
  javax.swing.JMenu jMenu2;
  javax.swing.JMenuBar jMenuBar1;
  javax.swing.JMenuItem jMenuItem1;
  javax.swing.JPanel jPanel1;
  javax.swing.JPanel jPanel10;
  javax.swing.JPanel jPanel11;
  javax.swing.JPanel jPanel2;
  javax.swing.JPanel jPanel3;
  javax.swing.JPanel jPanel4;
  javax.swing.JPanel jPanel5;
  javax.swing.JPanel jPanel6;
  javax.swing.JPanel jPanel7;
  javax.swing.JPanel jPanel8;
  javax.swing.JPanel jPanel9;
  javax.swing.JScrollPane jScrollPane1;
  javax.swing.JScrollPane jScrollPane2;
  javax.swing.JScrollPane jScrollPane3;
  javax.swing.JScrollPane jScrollPane4;
  javax.swing.JScrollPane jScrollPane5;
  javax.swing.JToolBar.Separator jSeparator1;
  javax.swing.JToolBar.Separator jSeparator2;
  javax.swing.JToolBar.Separator jSeparator3;
  javax.swing.JTabbedPane jTabbedPane1;
  javax.swing.JToolBar jToolBar1;
  javax.swing.JToolBar jToolBar2;
  javax.swing.JToolBar jToolBar3;
  public javax.swing.JList lst_chatUsers;
  javax.swing.JMenu mnu_arquivo;
  javax.swing.JMenu mnu_edit;
  javax.swing.JRadioButtonMenuItem rdb_duskSkin;
  javax.swing.JRadioButtonMenuItem rdb_graphiteSkin;
  javax.swing.JRadioButtonMenuItem rdb_officeBlueSkin;
  javax.swing.JRadioButtonMenuItem rdb_officeSilverSkin;
  public javax.swing.JTable tab_registereds;
  public javax.swing.JTable tab_users;
  public javax.swing.JTextPane txt_chatEdit;
  public javax.swing.JTextPane txt_chatPanel;
  // End of variables declaration//GEN-END:variables
}
